#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from lastfm import LastFMConnection
from lastfmqt import LastFMConnectionQt

lastfmqt = None

# handlers

def handleToken(link):

	print 'link:', link

def handleTokenError(message):

	print message

def handleSession():

	print 'success'

def handleSessionError(message):

	print message

def handleStation():

	print 'station success'

def handleStationError(message):

	print message

def handleTracks(tracks):

	for track in tracks:
		print track.artist, '-', track.title

def handleTracksError(message):

	print message

# other methods

def requestTracks():

	lastfmqt.connect(lastfmqt, SIGNAL('tracksSuccess(PyQt_PyObject)'), handleTracks)
	lastfmqt.connect(lastfmqt, SIGNAL('tracksFailure(QString)'), handleStationError)
	lastfmqt.requestTracks()

def requestStation():

	lastfmqt.connect(lastfmqt, SIGNAL('stationSuccess()'), requestTracks)
	lastfmqt.connect(lastfmqt, SIGNAL('stationFailure(QString)'), handleStationError)
	lastfmqt.requestStation('lastfm://user/helldrive/loved')

def requestSession():

	lastfmqt.connect(lastfmqt, SIGNAL('sessionSuccess()'), handleSession)
	lastfmqt.connect(lastfmqt, SIGNAL('sessionFailure(QString)'), handleSessionError)
	lastfmqt.requestSession()

def requestToken():

	lastfmqt.connect(lastfmqt, SIGNAL('tokenSuccess(QString)'), handleToken)
	lastfmqt.connect(lastfmqt, SIGNAL('tokenFailure(QString)'), handleTokenError)
	lastfmqt.requestToken()

app = QApplication(sys.argv)
app.setApplicationName('last.fm test app')

dialog = QWidget()
layout = QHBoxLayout()
button = QPushButton('OK', dialog)
layout.addWidget(button)
dialog.setLayout(layout)
dialog.resize(200, 20)
dialog.show()
#button.connect(button, SIGNAL('clicked()'), requestSession)

lastfmqt = LastFMConnectionQt(True)
#requestToken()
requestStation()

app.exec_ ()




